/**
 * 高级语法兼容， 使用regenator兼容async语法
 */
const regenerator = require('regenerator');
const fs = require('fs');
const path = require('path');

const sourcePath = path.join(__dirname, './source.js');
const source = fs.readFileSync(sourcePath, 'utf8');
const targetPath = path.join(__dirname, './target.js');

const result = regenerator.compile(source, {
    incluedeRuntime: true,
});

console.log(result.code);
fs.writeFileSync(targetPath, result.code);